//
//  Dc_HuaViewController.m
//  艾薇贝儿
//
//  Created by dllo on 15/9/17.
//  Copyright (c) 2015年 dllo－－邴鹏超. All rights reserved.
//

#import "Dc_HuaViewController.h"
#import "DcAFNetWorkTool.h"
#import "DcFirstModel.h"
#import "Dc_XinGeTableViewCell.h"
#import "Dc_PlayerSTK.h"
#import "Dc_Dan.h"
#import "AppDelegate.h"
#import "Reachability.h"
@interface Dc_HuaViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    UITableView * _tableView;
    NSMutableArray * _array;
    NSMutableArray * _picArray;
}
@end

@implementation Dc_HuaViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _array=[[NSMutableArray alloc]init];
    _picArray=[[NSMutableArray alloc]init];
    _tableView =[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 375  ,364 )];
    [_tableView setDataSource:self];
    [_tableView setDelegate:self];
    [self.view addSubview:_tableView];

   [DcAFNetWorkTool getUrl:@"http://api.songlist.ttpod.com/songlists/300002376?f=0&os=4.4.2&alf=10001791&imei=111111111111111&from=android&resolution=480x854&net=2&api_version=1.0&agent=none&v=v8.1.1.2015081317&utdid=VV2s9r3zhNgDALDQVlZ6OMqc&longitude=0.0&user_id=0&latitude=0.0&language=zh" body:nil result:DcJSON headerFlile:nil success:^(id result) {
       
       NSMutableArray  * array=[result objectForKey:@"songs"];
       for (NSMutableDictionary * dic in array) {
           DcFirstModel * model=[[DcFirstModel alloc]init];
           [model setValuesForKeysWithDictionary:dic];
           [_array addObject:model];
          
           
           NSMutableDictionary * dic1=[result objectForKey:@"image"];
           DcFirstModel * mod=[[DcFirstModel alloc]init];
           [mod setValuesForKeysWithDictionary:dic1];
           [_picArray addObject:mod];
           
       }
       [_tableView reloadData];
   } failure:^(NSError *error) {
       
       
   }];
    
    // Do any additional setup after loading the view.
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [_array count];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 75;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * cellId=@"cell";
    Dc_XinGeTableViewCell * cell =[tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell==0) {
        cell=[[Dc_XinGeTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault                                   reuseIdentifier:cellId];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }
    DcFirstModel * mo=[_array objectAtIndex:indexPath.row];
    [cell model:mo];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    DcFirstModel * mo=[_picArray  objectAtIndex:indexPath.row];
    NSURL *url=[NSURL URLWithString:mo.pic];
    [Dc_Dan shareDan].image=url;
    
    DcFirstModel *lis = [_array objectAtIndex:indexPath.row];
    NSDictionary *dic = [lis.auditionList objectAtIndex:0];
    NSString *url1 = [dic objectForKey:@"url"];
    
    [Dc_Dan shareDan].url = url1;
    [Dc_Dan shareDan].singname = lis.name;
    [Dc_Dan shareDan].singername=lis.singerName;
    [Dc_Dan shareDan].index = indexPath.row;
    [Dc_Dan shareDan].urlarray = _array;
    
    
    if (lis.auditionList.count >2) {
        NSDictionary *dic = [lis.auditionList objectAtIndex:1];
        NSString *url = [dic objectForKey:@"url"];
        [self playerMusicUrl:url];
    }if (lis.auditionList.count==1) {
        NSDictionary *dic = [lis.auditionList objectAtIndex:0];
        NSString *url = [dic objectForKey:@"url"];
        [self playerMusicUrl:url];
    }
    
}
- (void)playerMusicUrl:(NSString *)url
{
    
    Dc_PlayerSTK *stk = [Dc_PlayerSTK shareHandleController];
    
    
    [stk play:url];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
